clear all
set more off
cd "/Users/yasenov/Dropbox (IPL)/RefugeeBan/data/"

***********
***********
***********

use "WRAPS/wraps_fips.dta"
keep if year >= 2015

merge 1:1 fips year using "crime/crime.dta", keep(1 3) keepusing(property violent)
drop if _merge == 1  
drop _merge

merge 1:1 fips year using "demographics/demographics.dta", keep(1 3)
drop if _merge == 1 
drop _merge

tab year
recode year (2015=2016) (2018=2017)
tab year

gen lproperty_crime = log(property_crime + 1)
gen rproperty_crime = (property_crime / pop_total) * 100000

gen lviolent_crime = log(violent_crime + 1)
gen rviolent_crime = (violent_crime / pop_total) * 100000

gen lrefugees = log(refugees + 1)
gen rrefugees = (refugee / pop_total) * 100

collapse (mean) lproperty rproperty rviolent lviolent rrefugees lrefugees pop_total, by(year fips)

sum

reshape wide lproperty rproperty rviolent lviolent rrefugees lrefugees pop_total, i(fips) j(year)

gen d_rproperty_crime = rproperty_crime2017 - rproperty_crime2016
gen d_rviolent_crime = rviolent_crime2017 - rviolent_crime2016
gen d_rrefugees = rrefugees2017 - rrefugees2016

gen d_lproperty_crime = lproperty_crime2017 - lproperty_crime2016
gen d_lviolent_crime = lviolent_crime2017 - lviolent_crime2016
gen d_lrefugees = lrefugees2017 - lrefugees2016

****************
****************
****************

local if if abs(d_rproperty) <= 1000 & d_rrefugees > -.4

twoway (scatter d_rproperty d_rrefugees `if' [w = pop_total2016], msymbol(circle_hollow)) ///
	(lowess d_rproperty d_rrefugees `if' ), ///
	ytitle("{&Delta} Property Crime Rate {superscript:pre-post} ", size(med)) ///
	xtitle("{&Delta} Refugee Arrivals per Capita {superscript:pre-post} ", size(med)) ///
	legend(off) ///
	title("Property Crimes Rates") ///
	name(graph1_a, replace)

local if if abs(d_rviolent) <= 1000	 & d_rrefugees > -.4

twoway (scatter d_rviolent d_rrefugees `if' [w = pop_total2016], msymbol(circle_hollow)) ///
	(lowess d_rviolent d_rrefugees `if' ), ///
	ytitle("{&Delta} Violent Crime Rate {superscript:pre-post} ", size(med)) ///
	xtitle("{&Delta} Refugee Arrivals per Capita {superscript:pre-post} ", size(med)) ///
	legend(off) ///
	title("Violent Crimes Rates") ///
	name(graph1_b, replace)

****************
****************
****************

local if if abs(d_lproperty) <= 1

twoway (scatter d_lproperty d_lrefugees `if' [w = pop_total2016], msymbol(circle_hollow)) ///
	(lowess d_lproperty d_lrefugees `if' ), ///
	ytitle("% {&Delta} Property Crimes {superscript:pre-post} ", size(med)) ///
	xtitle("% {&Delta} Refugee Arrivals {superscript:pre-post} ", size(med)) ///
	legend(off) ///
	title("Log Property Crimes") ///
	name(graph1_c, replace)

local if if abs(d_lviolent) <= 1 
	
twoway (scatter d_lviolent d_lrefugees `if' [w = pop_total2016], msymbol(circle_hollow)) ///
	(lowess d_lviolent d_lrefugees `if' ), ///
	ytitle("% {&Delta} Violent Crimes {superscript:pre-post} ", size(med)) ///
	xtitle("% {&Delta} Refugee Arrivals {superscript:pre-post} ", size(med)) ///
	legend(off) ///
	title("Log Violent Crimes") ///
	name(graph1_d, replace)

graph combine graph1_a graph1_b graph1_c graph1_d, imargin(small)

graph export "../results/fig_d2016_17.pdf", replace
